#include("../../comm/ListHead.html")
<style>
</style>
<div class="layui-fluid layui-anim layui-anim-scale">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md2 height-auto width-14">
            <div class="layui-card height-scoll">
                <div id="tree_1" class="demo-tree demo-tree-box"></div>
            </div>
        </div>
        <div class="layui-col-md10 width-86">
            <div class="layui-card">
                <div class="card-search SearchTable">
                    <p style="float:right">
                        <input type="hidden" id="curr_id" name="curr_id" value="#(form.data.def_id??)"/>
                        <input type="hidden" id="sch_id" name="sch_id" value="#(form.data.sch_id??)"/>
                        <input type="hidden" id="coll_id" name="coll_id" value="#(form.data.coll_id??)"/>
                        <input type="hidden" id="titles" name="titles" value="#(form.data.def_title??)"/>
                        <input type="text" id="names" placeholder="专业名称" class="table-search-text width200"/>

                        <button class="layui-btn layui-btn-warm layui-btn-sm" lay-event="DoSearch">
                            搜索
                        </button>

                    </p>
                    当前位置 > <span id="navtitle" class="color_green">[#(form.data.sch_id??)]#(form.data.def_title??)</span> >
                    <span id="navtitle2">学院(系)列表</span>
                </div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="table_1" lay-filter="table_1"></table>

                    <script type="text/html" id="table_spe_title">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm btn-add" lay-event="AddSchSpecialty">
                                <i class="layui-icon">&#xe608;</i> 添加专业
                            </button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-edit" lay-event="EditSchSpecialty">修改</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-del" lay-event="DelSchSpecialty">删除</button>
                        </div>
                    </script>

                    <script type="text/html" id="table_coll_title">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm btn-add" lay-event="AddSchCollege">
                                <i class="layui-icon">&#xe608;</i> 添加学院(系)
                            </button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-edit" lay-event="EditSchCollege">修改</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-del" lay-event="DelSchCollege">删除</button>
                        </div>
                    </script>

                    <script type="text/html" id="temp_college">
                        <input type="checkbox" lay-skin="switch" field="status" msg="显示院系" value="{{d.coll_id}}" lay-text="显示|隐藏" lay-filter="ChangeCollegeTag" {{ d.status ? 'checked' : '' }}>
                    </script>
                    <script type="text/html" id="temp_specialty">
                        <input type="checkbox" lay-skin="switch" field="status" msg="显示专业" value="{{d.spe_id}}" lay-text="显示|隐藏" lay-filter="ChangeSpecialtyTag" {{ d.status ? 'checked' : '' }}>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript">

    layui.use(['myTable', 'table', 'form', 'myTree', 'myTool', 'drawer'], function () {
        admin = layui.admin, myTool = layui.myTool, form = layui.form, myTree = layui.myTree;
        var $ = layui.$;
        var curr_id = '#(form.data.def_id)';
        var coll_id = '#(form.data.coll_id)';
        treedata = #(form.data.tree);
        var tableindex = getCollege();
        var grade = 1;
        /**
         * 树渲染1
         */
        myTree.render({
            data: treedata, init: curr_id
            , click: function (obj) {
                var data = obj.data;
                if (data.turn) {
                    grade = data.datas.grade;
                    if (grade == 1) {
                        curr_id = data.id;
                        $("#sch_id").val(data.datas.schid);
                        $("#navtitle").html("" + data.title);
                        $("#navtitle2").html("学院(系)列表");
                        $("#titles").val(data.title);
                        tableindex = getCollege();
                        tableindex.reload({toolbar: '#table_coll_title', where: {schid: data.datas.schid}, page: {curr: 1}});
                    } else if (grade == 2) {
                        curr_id = data.id;
                        $("#coll_id").val(data.datas.id);
                        $("#navtitle").html(data.title);
                        $("#navtitle2").html("专业列表");
                        $("#titles").val(data.title);
                        tableindex = getSpecialty();
                        tableindex.reload({toolbar: '#table_spe_title', where: {coll_id: data.datas.collid}, page: {curr: 1}});
                    }
                }
            }
        });


        /**
         * 表格
         */
        function getSpecialty() {
            return layui.myTable.render({
                elem: '#table_1', url: 'TestTable2ListDataApi'
                , title: '学校专业表', toolbar: '#table_spe_title'
                , where: {pub_tag: $("#coll_id").val()}
                , cols: [[
                    {type: 'checkbox', width: 36}
                    , {field: 'test_id', title: '专业ID', width: 100, align: 'center'}
                    , {field: 'test_name', title: '专业名称'}
                    , {field: 'sch_name', title: '学校名', width: 200}
                    , {field: 'coll_name', title: '院系名称', width: 200}
                    , {field: 'sindex', title: '显示顺序', width: 80, edit: 'text', align: 'center'}
                    , {field: 'ishide', title: '状态', width: 100, align: 'center', templet: '#temp_specialty'}

                ]]
                , page: true, limit: 10
                , serviceSort: true, initSort: {field: 'spe_id', type: 'desc'}
                , editField: {url: 'ModifySchSpecialtyFieldApi', key: 'spe_id'}
            });
        }


        /**
         * 表格
         */
        function getCollege() {
            return layui.myTable.render({
                elem: '#table_1', url: 'TestTable2ListDataApi'
                , title: '学校院系表', toolbar: '#table_coll_title'
                , where: {pub_tag: 1}
                , cols: [[
                    {type: 'checkbox', width: 36}
                    , {field: 'test_id', title: '院系ID', width: 100, align: 'center'}
                    , {field: 'test_name', title: '院系名称'}
                    , {field: 'sch_name', title: '学校名', width: 200}
                    , {field: 'sindex', title: '显示顺序', width: 80, edit: 'text', align: 'center'}
                    , {field: 'ishide', title: '状态', width: 100, align: 'center', templet: '#temp_college'}
                ]]
                , page: true, limit: 10
                , serviceSort: true, initSort: {field: 'coll_id', type: 'desc'}
                , editField: {url: 'ModifySchCollegeFieldApi', key: 'coll_id'}
            });
        }

        /**
         * 按钮事件
         */
        layui.util.event("lay-event", {
            DoSearch: function () {
                if (grade == 1) {
                    tableindex.config.where = {schid: $("#sch_id").val(), s: {coll_name: $("#names").val()}};
                    tableindex.reload({where: tableindex.config.where, page: {curr: 1}});
                } else {
                    tableindex.config.where = {coll_id: $("#coll_id").val(), s: {spe_name: $("#names").val()}};
                    tableindex.reload({where: tableindex.config.where, page: {curr: 1}});
                }
            }
            , DoSearchMore: function () {
                layui.form.render();
                drawer1.open();
            }
        });

        /**
         * 工具栏事件
         */
        layui.table.on('toolbar(table_1)', function (obj) {
            myTool.toolbar(this, obj, {
                AddSchSpecialty: function () {
                    index = top.layer.open({
                        type: 2, offset: '100px', area: ['700px', '450px'], title: ['添加院系专业', 'font-size:15px;'],
                        content: ["schschool/AddSchSpecialty?coll_id=" + $("#coll_id").val(), 'no'],
                        end: function () {
                            tableindex.reload({});
                        }
                    });
                }
                , EditSchSpecialty: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = top.layer.open({
                            type: 2, offset: '100px', area: ['700px', '450px'], title: ['修改学校专业[' + data[0].spe_id + ']', 'font-size:15px;'],
                            content: ["schschool/EditSchSpecialty?spe_id=" + data[0].spe_id, 'no'],
                            end: function () {
                                tableindex.reload({});
                            }
                        });
                    });
                }
                , DelSchSpecialty: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = layer.confirm('你是否确认删除学校专业【' + data[0].spe_id + '】', {icon: 3, title: '提示', offset: '100px'}, function (index2) {
                            myTool.postMsg("DelSchSpecialtyApi", {
                                spe_id: data[0].spe_id
                            }, function () {
                                layer.close(index2);
                                tableindex.reload();
                            });
                        });
                    });
                }
                , AddSchCollege: function () {
                    index = top.layer.open({
                        type: 2, offset: '100px', area: ['700px', '450px'], title: ['添加院系专业', 'font-size:15px;'],
                        content: ["schschool/AddSchCollege?sch_id=" + $("#sch_id").val(), 'no'],
                        end: function () {
                            tableindex.reload({});
                        }
                    });
                }
                , EditSchCollege: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = top.layer.open({
                            type: 2, offset: '100px', area: ['700px', '450px'], title: ['修改院系[' + data[0].coll_name + ']', 'font-size:15px;'],
                            content: ["schschool/EditSchCollege?coll_id=" + data[0].coll_id, 'no'],
                            end: function () {
                                tableindex.reload({});
                            }
                        });
                    });
                }
                , DelSchCollege: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = layer.confirm('你是否确认删除学校专业【' + data[0].spe_id + '】', {icon: 3, title: '提示', offset: '100px'}, function (index2) {
                            myTool.postMsg("DelSchCollegeApi", {
                                spe_id: data[0].spe_id
                            }, function () {
                                layer.close(index2);
                                tableindex.reload();
                            });
                        });
                    });
                }
            });
        });
        form.on('switch(ChangeCollegeTag)', function (obj) {
            myTool.postMsg("ChangeCollegeTagApi", {key: this.value, field: $(obj.elem).attr("field"), msg: $(obj.elem).attr("msg")}, function (result) {
                layer.tips(result.msg, obj.othis);
            });
        });
        form.on('switch(ChangeSpecialtyTag)', function (obj) {
            myTool.postMsg("ChangeSpecialtyTagApi", {key: this.value, field: $(obj.elem).attr("field"), msg: $(obj.elem).attr("msg")}, function (result) {
                layer.tips(result.msg, obj.othis);
            });
        });
    });
</script>
#include("../../comm/Foot.html")